package com.itheima.comment.controller;

import com.itheima.comment.dto.CommentDto;
import com.itheima.comment.dto.CommentSaveDto;
import com.itheima.comment.service.CommentService;
import com.itheima.comment.vo.CommentVo;
import com.itheima.common.vo.ResultVo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @version 1.0
 * @description 说明
 * @package com.itheima.comment.controller
 */
@RestController
@RequestMapping("/comment")
public class CommentController {

    @Resource
    private CommentService commentService;

    @PostMapping("/save")
    public ResultVo addComment(@RequestBody CommentSaveDto dto){
        commentService.add(dto);
        return ResultVo.ok("操作成功");
    }

    /**
     * 加载评论列表
     * @param dto
     * @return
     */
    @PostMapping("/load")
    public ResultVo<List<CommentVo>> load(@RequestBody CommentDto dto){
        List<CommentVo> voList = commentService.load(dto);
        return ResultVo.ok(voList);
    }
}
